package com.kate.order.servlet;

import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kate.order.entity.Order;
import com.kate.order.mapper.OrderMapper;
import com.kate.order.response.ServerResponse;
import com.kate.order.service.IOrderService;
import com.kate.order.service.impl.OrderServiceImpl;
import com.kate.order.util.SqlSessionUtil;
import lombok.SneakyThrows;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 新梦想.陈超
 * @version 2021.2
 * @Description: {TODO}
 * @date 2023/7/10 上午8:51
 */

@WebServlet(name="ListOrderServlet",urlPatterns = "/list")
public class ListOrderServlet extends HttpServlet {
    private Logger log = Logger.getLogger(ListOrderServlet.class);
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //TODO 1.校验请求参数
        int page = 1;//默认第1页
        String pageStr = req.getParameter("page");
        if(pageStr!=null){
            page = Integer.parseInt(pageStr);
        }
        //TODO 2.调用业务层service
        IOrderService orderService = new OrderServiceImpl();
        final ServerResponse serverResponse = orderService.list(page, 3);

        //TODO 3.返回响应
        resp.setContentType("text/html;charset=utf8");
        resp.getWriter().write(JSON.toJSONString(serverResponse));
    }
}
